package com.hc.springbootredis.controller;

import com.hc.springbootredis.entity.Comment;
import com.hc.springbootredis.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class CommentController {
    @Autowired
    @Qualifier("CommentService2")
    CommentService commentService;

    @RequestMapping("find/{id}")
    public Comment findById(@PathVariable Integer id){
        return commentService.findById(id);
    }

    @RequestMapping("update/{id}/{author}")
    public Comment updateComment(@PathVariable String author,@PathVariable Integer id){
        Comment comment = commentService.findById(id);
        comment.setAuthor(author);
        return commentService.updateComment(comment);
    }

    @RequestMapping("delete/{id}")
    public void deleteById(@PathVariable Integer id){
        commentService.deleteById(id);
    }
}
